package com.chao.ClientSocket;

import org.junit.Test;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.Socket;
import java.net.SocketAddress;

public class SocketInnetAddress {

    public static void main(String[] args) throws IOException {
        Socket socket=new Socket();
        SocketAddress address = new InetSocketAddress("time.nist.gov", 13);
        socket.connect(address);
        socket.close();

        Socket socket1=new Socket("www.yahoo.com",80);
        SocketAddress yahoo = socket1.getRemoteSocketAddress();
        System.out.println(socket1.isConnected());
        System.out.println(yahoo);
        socket1.close();
    }


    @Test
    public void proxy() throws IOException {
        InetSocketAddress proxyAddress = new InetSocketAddress("somproxy.com", 1080);
        Proxy proxy=new Proxy(Proxy.Type.SOCKS,proxyAddress);
        Socket socket=new Socket(proxy);
        InetSocketAddress remote = new InetSocketAddress("login.com", 25);


        System.out.println(socket.getLocalAddress());
        System.out.println(socket.getRemoteSocketAddress());
        System.out.println(socket.getPort());
        System.out.println(socket.getLocalPort());

        socket.connect(remote);

        socket.close();

    }


}
